import os
import shutil

from utils.file_io import file_r, file_w

if __name__ == '__main__':
    sound_root_path = "wav"
    transcript_root_path = "transcript"
    transcript_text = file_r(transcript_root_path + "/transcript.txt")
    transcript_text_new = ""
    is_full_old_name = 1
    count = 1
    if not os.path.exists(sound_root_path+"/output_rename_by_txt/"):
        os.mkdir(sound_root_path+"/output_rename_by_txt/")
    for line in transcript_text.split("\n"):
        if len(line) == 0:
            continue
        line_file_name = line.split(" ")[0]
        line_file_txt = "".join(line.split(" ")[1:])
        if is_full_old_name == 1:
            line_file_name_new = line_file_name+"_"+line_file_txt
        else:
            line_file_name_new = line_file_txt
        transcript_text_new = transcript_text_new + line_file_name_new + " " + line_file_txt + "\n"
        shutil.copy(sound_root_path+"/output/"+line_file_name+".wav", sound_root_path+"/output_rename_by_txt/"+line_file_name_new+".wav")
        count = count+1
    file_w(transcript_root_path + "/transcript_rename_by_txt.txt", transcript_text_new, "a")



